<!--
 * @Author: 莫卓才
 * @eMail: handsome.mo@foxmail.com
 * @Descripttion: 描述
 * @version: 1.0.0
 * @Date: 2020-02-20 18:16:13
 * @LastEditors: 莫卓才
 * @LastEditTime: 2020-06-12 19:30:14
 -->
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
  style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <div class="layui-input-inline" style="width: 450px;">
      <script type="text/html" template>
        <input type="text" name="title" id="title" value="{{ d.params.title || '' }}" lay-verify="required" placeholder="相片标题" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-inline">
      <script type="text/html" template lay-url="/api/photos/getCategoryList" lay-done="layui.form.render('select');"
        lay-data="{'lang': layui.data('lang').lang}">
        <select name="category_id" id="category_id" lay-verify="required" >
             <option value="">分类选择</option>
              {{# layui.each(d.data,function(index,item){ }}
                <option value="{{ item.id }}" {{ item.title === d.params.category_name ? 'selected' : '' }}>{{ item.title }}</option>
              {{# }); }}
        </select>
       </script>
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <div class="layui-input-inline" style="width: 450px;">
      <script type="text/html" template>
      <textarea name="description" placeholder="照片描述" class="layui-textarea">{{ d.params.description || '' }}</textarea>
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-inline" style="width: 345px;">
      <script type="text/html" template>
        <input type="text" name="thumb" id="thumb" value="{{ d.params.thumb || '' }}"  lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
      </script>
    </div>
    <button style="float: left;" type="button" class="layui-btn" id="layuiadmin-upload-thumb">上传图片</button>
  </div>
  <!--<div class="layui-form-item">-->
  <!--  <label class="layui-form-label">省略图地址</label>-->
  <!--  <div class="layui-input-inline" style="width: 345px;">-->
  <!--    <script type="text/html" template>-->
  <!--      <input type="text" name="path" id="path" value="{{ d.params.path || '' }}"  placeholder="上传图片后自动生成" autocomplete="off" class="layui-input" autocomplete="off">-->
  <!--    </script>-->
  <!--  </div>-->
  <!--</div>-->
  <div class="layui-form-item">
    <div class="layui-form-item">
      <div class="layui-input-inline">
        <script type="text/html" template>
        <input type="checkbox" lay-filter="status" name="status" lay-skin="switch" lay-text="显示|隐藏" {{ d.params.status != 0 ? 'checked' : '' }} >
      </script>
      </div>
    </div>
    <script type="text/html" template>
    <input type="hidden" name="id" value="{{ d.params.id || '' }}">
  </script>
    <script type="text/html" template>
    <input type="hidden" name="lang" value="{{ layui.data('lang').lang }}">
  </script>
    <div class="layui-form-item">
      <div class="layui-input-inline">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
      </div>
    </div>
  </div>
  <script type="text/html" template>
    {{#
      if(d.params.path!=''&&d.params.path!=undefined&&d.params.category_id!=3){
    }}
      <div class="layui-form-item">
        <div class="layui-input-inline" style="width: 345px;">
          <img src="{{ d.params.thumb }}" height="260">
        </div>
      </div>
    {{#
      }
    }}
  </script>
</div>
  <script>
    layui.use(['admin', 'form', 'upload', 'laydate'], function () {
      var $ = layui.$
        , form = layui.form
        , upload = layui.upload;
      var laydate = layui.laydate;
      var path = $('#path'); // 省略图
    //   var title = $('#title'); 
      //日期时间选择器
        
      upload.render({
        elem: '#layuiadmin-upload-thumb'
        , url: '/api/uploads/photos/column/photos'
        , accept: 'file'
        , method: 'get'
        // ,acceptMime: 'image/*'
        , done: function (res) {
            if(res.code === 0){ //返回验证 0为成功
                $("#thumb").val(res.data.src);
                $("#path").val(res.data.path);
                $("#title").val(res.data.title);
                layer.msg(res.msg, {icon: 6});
                console.log(res.data.src,res.data.title);
            }else{
                layer.msg(res.msg, {icon: 5});
                // console.log(res.msg);
            }
        }
      });

      form.on('radio(status)', function (data) {
        // console.log(data.elem); //得到radio原始DOM对象
        console.log(data.value); //被点击的radio的value值
      });

    })
    function createTime() {
      var laydate = layui.laydate;

      laydate.render({
        elem: '#test5'
        , type: 'datetime'
        , show: true
      });
    }
  </script>